define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'csmwj/paper/index' + location.search,
                    add_url: 'csmwj/paper/add',
                    edit_url: 'csmwj/paper/edit',
                    del_url: 'csmwj/paper/del',
                    multi_url: 'csmwj/paper/multi',
                    import_url: 'csmwj/paper/import',
                    table: 'csmwj_paper',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        { checkbox: true },
                        { field: 'id', title: __('Id') },
                        // { field: 'locales', title: __('Locales'), searchList: { "zh": __('Locales zh'), "en": __('Locales en') }, formatter: Table.api.formatter.normal },
                        { field: 'name', title: __('Name'), operate: 'LIKE' },
                        { field: 'demo', title: '备注', operate: 'LIKE' },
                        // { field: 'cfghastimelimit', title: __('Cfghastimelimit'), searchList: { "Y": __('Cfghastimelimit y'), "N": __('Cfghastimelimit n') }, formatter: Table.api.formatter.normal },
                        // { field: 'cfgbegintime', title: __('Cfgbegintime'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime },
                        // { field: 'cfgendtime', title: __('Cfgendtime'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime },
                        { field: 'status', title: __('Status'), searchList: { "normal": '正常', "hidden": '隐藏', "draft": '草稿' }, formatter: Table.api.formatter.status },
                        {

                            field: 'operate',
                            title: __('Operate'),
                            table: table, events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'edit',
                                    text: __('设置'),
                                    classname: 'btn btn-xs btn-success btn-click',
                                    click: function (res, row) {
                                        window.open(Fast.api.fixurl("csmwj/paper/edit/ids/" + row.id + "?dialog=1"));
                                    },
                                },
                                // {
                                //     name: 'confqdcode',
                                //     text: __('入口'),
                                //     classname: 'btn btn-xs btn-info btn-dialog',
                                //     visible: function (row) {
                                //         if (row.status == 'normal') {
                                //             return true;
                                //         } else {
                                //             return false;
                                //         }
                                //     },
                                //     url: Fast.api.fixurl("csmwj/paper/port"),
                                // },
                                {
                                    name: 'statisic',
                                    text: __('结果'),
                                    classname: 'btn btn-xs btn-warning btn-click',
                                    click: function (res, row) {
                                        window.open(Fast.api.fixurl("csmwj/paperstatistic/index?id=" + row.id + "&dialog=1"));
                                    },
                                },
                            ]
                        },
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        },
        port: function(){
            let that = this;
            $("#xp-block-mp-"+Config.csmwj.cloginwxmp).removeClass("hidden");
        }
    };
    return Controller;
});
